package org.alex.samples.controller;


import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.alex.samples.model.ExamScoreVO;
import org.alex.samples.service.ITeacherService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
@RequestMapping(value = "/teacher")
public class ScoreController {
	
	@Autowired
	private ITeacherService teacherService;
	
	@RequestMapping(value = "/score")
	public String getAllScore(Model model){
		 List<ExamScoreVO> list = teacherService.findAllScore();
		 model.addAttribute("ScoreList", list);
		return "score/score";
	}
	
	@ResponseBody
	@RequestMapping(value = "/select")
	public Map<String,Object> getAllScoreBySel(String selContext,String seltType){
		
		Map<String,Object> resultMap = new HashMap<String,Object>();
		resultMap.put("success", false);
		List<ExamScoreVO> list;
		try {
			list = teacherService.findScoreBySelContext(selContext,seltType);
			if(list.size() > 0){
				resultMap.put("success", true);
				resultMap.put("ScoreListBySel", list);
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
		
		return resultMap;
	}

}
